// 导入获取导航数据函数
import { getUserChannels, getAllChannels } from '@/api/channel'

export default {
  state: {
    channelList: [],
    allChannelList: []
  },
  mutations: {
    setChannelList(state, payload) {
      state.channelList = payload
    },
    addChannelList(state, payload) {
      state.channelList.push(payload)
    },
    setAllChannelList(state, payload) {
      state.allChannelList = payload
    },
    delChannelList(state, payload) {
      state.channelList = state.channelList.filter(
        (item) => item.id !== payload.id
      )
    }
  },
  getters: {
    optionsChannelList(state) {
      return state.allChannelList.filter(
        (item) => !state.channelList.some((index) => index.id === item.id)
      )
    }
  },
  actions: {
    async ctions_getChannelList(context) {
      // 获取导航数据
      const { data } = await getUserChannels()
      context.commit('setChannelList', data.channels)
    },

    async actions_getAllChannelList(context) {
      const res = await getAllChannels()
      context.commit('setAllChannelList', res.data.channels)
    }
  },
  namespaced: true
}
